#include "memdb/error/MemdbError.h"

namespace memdb {
namespace error {

const char * MemdbErrorCategory::name() const noexcept {
	return "db_error_category";
}

/*
std::error_condition MemdbErrorCategory::default_error_condition(int ev) const noexcept{
	return std::error_category::default_error_condition(ev);
}*/

std::string MemdbErrorCategory::message(int ev) const {

	static const char * ErrorString[] = {
		"ok",
		"error",

		"table_not_exists",
		"table_exists",

		"key_not_exists",
		"key_exists",

		"db_not_exists",
		"db_exists",

		"fs_create_directory_error",

		"meta_info_absent",
		"operation_failed",
    };
    auto isValidCode = [](const int code) -> bool{
      return  code > 0 && code < (int)(memdb::error::max_error_no);
    };
		return isValidCode(ev) ? std::string(ErrorString[ev]) : std::string("unknown memdb error category errno:").append(std::to_string(ev));
}

}//namespace error
}//namespace memdb
